package com.dospyer.stream.controller;

import com.dospyer.stream.topic.StreamTopic;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {

    @Resource
    private StreamTopic testTopic;

    /**
     * 消息生产接口
     *
     * @param message
     * @return
     */
    @GetMapping("/sendMessage")
    public String messageWithMQ(@RequestParam String message) {
        testTopic.output().send(MessageBuilder.withPayload(message).setHeader("version", "1.0").build());
        testTopic.output().send(MessageBuilder.withPayload(message).setHeader("version", "2.0").build());
        return "ok";
    }

}